package 函数式编程

object 遍历操作 {
  def main(args: Array[String]): Unit = {
    /*
    遍历List
     */
    //    val list = List(1,2,3)
    //    val f = (i:Int) => println(i)
    //    list.foreach(f)
    //
    //    list foreach(i => println(i))
    //    list foreach println

    /**
     * 遍历Map
     */
    val map = Map("name" -> "Jack", "age" -> "21")
    //详细写法
    map foreach { kv => println(kv._1 + ":" + kv._2) }
    //简写
    map foreach { x =>
      x match {
        case (k, v) => println(k + ":" + v)
      }
    }
    map foreach { case (k, v) => println(k + ":" + v) }

  }
}
